package mka.puzzle.draw;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.util.ArrayList;

import javax.swing.JPanel;

import mka.puzzle.cartesian.Axis;
import mka.puzzle.shape.Circle;
import mka.puzzle.shape.Eclipse;
import mka.puzzle.shape.Line;
import mka.puzzle.shape.Rectangle;
import mka.puzzle.shape.Shape;
import mka.puzzle.shape.Square;
import mka.puzzle.shape.Triangle;

public class PaintShape extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * Dimension of Frame
	 */
	protected int width = 500;
	protected int height = 500;
	
	private ArrayList<Shape> shapeList;
	
	/**
	 * Constructor
	 */
	public PaintShape() {
		this.shapeList = new ArrayList<Shape>();
	}
	
	/**
	 * Constructor
	 */
	public PaintShape(Shape shape) {
		this.shapeList = new ArrayList<Shape>();
		this.shapeList.add(shape);
	}
	
	@Override
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		Graphics2D g2d = (Graphics2D) g;
		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
				RenderingHints.VALUE_ANTIALIAS_ON);
		g2d.setColor(new Color(30, 131, 34));
		
		for(Shape shape : shapeList) {
//			drawShape(g2d, shape);
			shape.draw(g2d);
		}
	}
	
	public void addShape(Shape shape) {
		this.shapeList.add(shape);
	}
	
	public void removeShape() {
		this.shapeList.remove(0);
	}

	public void drawShape(Graphics g, Shape shape) {
		if ("Circle".equals(shape.getName())) {
			Circle circle = (Circle) shape;
//			g.drawOval((int) (circle.getCenter().getX() - circle.getRadius()),
//					(int) (circle.getCenter().getY() - circle.getRadius()),
//					(int) circle.getRadius(), (int) circle.getRadius());
			circle.draw(g);
		} else if ("Line".equals(shape.getName())) {
			Line line = (Line) shape;
//			g.drawLine((int) line.getPointBegin().getX(), (int) line
//					.getPointBegin().getY(), (int) line.getPointEnd().getX(),
//					(int) line.getPointEnd().getY());
			line.draw(g);
		} else if ("Square".equals(shape.getName())) {
			Square square = (Square) shape;
//			g.drawRect((int) square.getLeftTopPoint().getX(), (int) square
//					.getLeftTopPoint().getY(), (int) square.getSide(),
//					(int) square.getSide());
			square.draw(g);
		} else if ("Axis".equals(shape.getName())) {
			Axis axis = (Axis) shape;
//			g.drawLine((int) axis.getAxisX().getPointBegin().getX(), (int) axis.getAxisX()
//					.getPointBegin().getY(), (int) axis.getAxisX().getPointEnd().getX(),
//					(int) axis.getAxisX().getPointEnd().getY());
//
//			g.drawLine((int) axis.getAxisY().getPointBegin().getX(), (int) axis.getAxisY()
//					.getPointBegin().getY(), (int) axis.getAxisY().getPointEnd().getX(),
//					(int) axis.getAxisY().getPointEnd().getY());
			axis.drawAxis(g);
		} else if ("Rectangle".equals(shape.getName())) {
			Rectangle rectangle = (Rectangle) shape;
			rectangle.draw(g);
		} else if ("Eclipse".equals(shape.getName())) {
			Eclipse eclipse = (Eclipse) shape;
			eclipse.draw(g);
		} else if ("Hyperbola".equals(shape.getName())) {
			
		} else if ("Parabola".equals(shape.getName())) {
			
		} else if ("Triangle".equals(shape.getName())) {
			Triangle triangle = (Triangle) shape;
			triangle.draw(g);
		}
	}
}
